package com.ywger.service.result;


import com.ywger.integration.constants.IntegrationResultCode;
import com.ywger.service.constants.ResultCode;
import lombok.Data;

/**
 * @author che nmeng
 * @date  2021-07-06 15:29:06
 * @desc 统一返回结果
 */
@Data
public class Result<T> {

    private String code;

    private String message;


    private T detail;



    public static Result ofSuccess(){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.name());
        result.setMessage(ResultCode.SUCCESS.getDesc());
        result.setDetail(null);
        return result;
    }
    public static <T> Result<T> ofSuccess(T detail) {
        Result<T> result = new Result<T>();
        result.setCode(ResultCode.SUCCESS.name());
        result.setMessage(ResultCode.SUCCESS.getDesc());
        result.setDetail(detail);
        return result;
    }

    public static Result ofError(ResultCode resultCode) {
        Result result = new Result();
        result.setCode(resultCode.name());
        result.setMessage(resultCode.getDesc());
        return result;
    }

    public static Result ofError(IntegrationResultCode resultCode) {
        Result result = new Result();
        result.setCode(resultCode.getName());
        result.setMessage(resultCode.getDesc());
        return result;
    }


    public static Result ofError(String code,String desc){
        Result result = new Result();
        result.setCode(code);
        result.setMessage(desc);
        return result;
    }

}
